<?php
    
    require_once('../../SiteIncludes.GLOBAL.php');
    
    if(EclipseMDE::runningOnMod_Rewrite() === false) {
	// Security Guard, Do Not Let This be accessed by any other means than mod_rewrite
	$gVAR['e'] = '404';
	require_once('error_handler.php');
	die();
    }
    
    if(isset($_LOGGEDINUSER) === true && $_LOGGEDINUSER !== false && $_LOGGEDINUSER->get_priv_adm() === true) {
	
        $usx_online = UserSession::countActiveSessions();
        $lax_html = '';
        $busy_html = '';
        
        // Number of logged in users (Active in last 5 minutes).
        $topx_html = '<b>Users Online</b>: '.$usx_online;
        // If on linux - Print load average
        if(function_exists('sys_getloadavg') === true) {
            $lavg = sys_getloadavg();
            $lax_online = implode($lavg, ', ');
            $lax_html = ' | <b>Load Average</b>: '.$lax_online;
            // If on linux and we can detect cores, print out how busy we are
            if(file_exists('/proc/cpuinfo') === true) {
                $cpuinfo_num_threads = count(preg_grep('/processor/', explode("\n", file_get_contents('/proc/cpuinfo'))));
                $busyness = $lavg[0] / $cpuinfo_num_threads;
                if($busyness < 0.10) {
                    $busyinfo = '<font color="#006600">Light</font>';
                } elseif($busyness < 0.4) {
                    $busyinfo = '<font color="#337700">Normal</font>';
                } elseif($busyness < 0.8) {
                    $busyinfo = '<font color="#777700">Moderate</font>';
                } elseif($busyness < 1.35) {
                    $busyinfo = '<font color="#a03300">Heavy</font>';
                } else {
                    $busyinfo = '<font color="#ff0000">Overloaded</font>';
                }
                $busy_html = ' | <b>Load Info</b>: '.$busyinfo;
            }
        }
        $TemplateEngine->create_content_html(
            $Templater->makeTopDiv($topx_html.$lax_html.$busy_html)
        );
        
	$admin_home_html = <<<EOHTML
	
	<div id="admin_home">
	    <div class="row-fluid">
		<div class="span3" style="text-align: center;"></div>
		<div class="span6" style="text-align: center;">
		    <table class="width: 100%; margin-left: auto; margin-right: auto;">
			<tr>
			    <td>
				<a href="/admin/user"><img src="" class="naviconimg" alt="" /><br />User Admin</a>
			    </td>
			    <td>
				<a href="/admin/project"><img src="" class="naviconimg" alt="" /><br />Project Admin</a>
			    </td>
			</tr>
		    </table>
		</div>
	    </div>
	</div>
	
EOHTML;
	
	$TemplateEngine->create_content_html($admin_home_html);
	$TemplateEngine->setHasSidebar(false);
	$TemplateEngine->setCentralContentFullWidth(true);
	$TemplateEngine->render();
    } else {
	$gVAR['e'] = 403;
	require_once('../error_handler.php');
	die();
    }
?>
